/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package businessDelegates;

import businessObjects.Pais;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionFacades.PaisFacadeRemote;

/**
 *
 * @author williamprado
 */
@EJB(name="paisfr", beanInterface = PaisFacadeRemote.class)
public class PaisBusinessDelegate {

    public PaisBusinessDelegate(){

    }

    public void insertarPais(Pais pais){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            paisFacadeBean.insertarPais(pais);
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Pais consultarPais(String twolettercode){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            Pais pais = paisFacadeBean.consultarPais(twolettercode);
            return pais;
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public Pais buscarPaisPorNombre(String nombrePais){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            Pais pais = paisFacadeBean.buscarPaisPorNombre(nombrePais);
            return pais;
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public List<Pais> todosLosPaises(){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            List<Pais> lp = paisFacadeBean.todosLosPaises();
            return lp;
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public void actualizarPais(Pais pais){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            paisFacadeBean.actualizarPais(pais);
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void eliminarPais(String twolettercode){
        try {
            Context ctx = new InitialContext();
            PaisFacadeRemote paisFacadeBean = (PaisFacadeRemote) ctx.lookup("java:comp/env/paisfr");
            paisFacadeBean.eliminarPais(twolettercode);
        } catch (NamingException ex) {
            Logger.getLogger(PaisBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
